﻿using SHKF.B2C.Model.Dto.Center;
using SHKF.B2C.Model.Dto.WorkingCenter;
using SHKF.B2C.Model.Entity.Center;
using SHKF.B2C.Model.Entity.WorkingCenter;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WQDSkin.Forms.Component;

namespace SHKF.B2C.Mannage.AdminUI.View.WorkingCenter.DataWarehousInfo
{
    /// <summary>
    /// frmDataWarehousInfoEdit.xaml 的交互逻辑
    /// </summary>
    public partial class frmDataWarehousInfoEdit : BasePage
    {
        public frmDataWarehousInfoEdit()
        {
            InitializeComponent();
        }

        private async void btnSave_Click(object sender, RoutedEventArgs e)
        {
            DataWarehousInfoEntity data = (DataWarehousInfoEntity)this.DataContext;
            if (data == null)
            {
                data = new DataWarehousInfoEntity();
            }

            DataWarehousInfoDto dto = await GL.HttpClientManage.SaveDataWarehousInfo(data);
            if (dto.error == null)
            {
                MessageBox.Show("保存成功!");
                this.DataContext = dto.data;
            }
            else
            {
                MessageBox.Show(dto.error.msg);
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            base.Contain.CallBack(this.DataContext);
        }

        private void cbxServerName_SelectionChanged(object sender, SelectionChangedEventArgs e)
        { 
            this.txtServerName.Text = ((ComboBoxItem)this.cbxServerName.SelectedItem).Content.ToString();
        }

        private async void BasePage_Loaded(object sender, RoutedEventArgs e)
        {
            ErpServerListDto dto = await GL.HttpClientManage.QueryErpServer();
            if( dto.error == null)
            {
                this.cbxServerName.Items.Clear();
                foreach (ErpServerEntity server in dto.data)
                {
                    ComboBoxItem item = new ComboBoxItem();
                    item.Content = server.ServerName;
                    this.cbxServerName.Items.Add(item);
                }
            }
        }
    }
}
